var chSeqs = ["一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二", "十三", "十四", "十五", "十六", "十七", "十八", "十九"];
$(function(){
	initIndex();
	prettyPre();
})
function initIndex(){
	var $aside = $("<aside></aside>");
	$("section").each(function(index, element){
		var $section = $(this);
		var $sectionTitle = $("h1", $section);
		var sectionTitle = $sectionTitle.text();
		sectionTitle = chSeqs[index]+"、 "+sectionTitle;
		$sectionTitle.text(sectionTitle);
		$section.attr("id", "section-"+(index+1));
		$aside.append('<h3><a href="#section-'+(index+1)+'">'+sectionTitle+'</a></h3>');
		var $asideOl = $("<ol></ol>");
		$("article", $section).each(function(indexa, elementa){
			var $article = $(this);
			var $articleTitle = $("h2", $article);
			var articleTitle = (indexa+1)+". "+$articleTitle.text();
			$articleTitle.text(articleTitle);
			var articleId = "article-"+(index+1)+"."+(indexa+1);
			$article.attr("id", articleId);
			$asideOl.append('<li><a href="#'+articleId+'">'+articleTitle+'</a></li>');
		});
		$aside.append($asideOl);
	});
	$("body").prepend($aside);
}
function prettyPre(){
	$("pre").each(function(){
		var preString = $.trim($(this).text());
		var preStrArray = preString.split("\n");
		var finalString = "";
		for(var i in preStrArray){
			var preLine = preStrArray[i];
			var ti = preLine.indexOf("//");
			if(ti>=0)finalString += preLine.substring(0, ti)+"<s>"+preLine.substring(ti)+"</s>\n";
			else finalString += preLine + "\n";
		}
		$(this).html(finalString);
	})
}